package com.gisocn.onemap.base;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import androidx.multidex.MultiDexApplication;
import com.dreamlive.cn.clog.CollectLog;
import com.gisocn.onemap.greendao.DaoMaster;
import com.gisocn.onemap.greendao.DaoSession;
import com.hjq.toast.ToastUtils;
import com.tencent.smtt.sdk.QbSdk;
import org.greenrobot.greendao.query.QueryBuilder;

/* loaded from: classes.dex */
public class MyApplication extends MultiDexApplication {
    private static final String DB_NAME = "onemap_file";
    public static MyApplication instances;
    public static Context mContext;
    QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() { // from class: com.gisocn.onemap.base.MyApplication.1
        @Override // com.tencent.smtt.sdk.QbSdk.PreInitCallback
        public void onViewInitFinished(boolean z) {
            Log.e("APPAplication", " onViewInitFinished is " + z);
        }

        @Override // com.tencent.smtt.sdk.QbSdk.PreInitCallback
        public void onCoreInitFinished() {
            Log.e("APPAplication", " onCoreInitFinished");
        }
    };
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    private DaoMaster.DevOpenHelper mHelper;

    @Override // android.app.Application
    public void onCreate() {
        super.onCreate();
        instances = this;
        mContext = getApplicationContext();
        ToastUtils.init(instances);
        setDatabase();
        CollectLog.getInstance().init(this, Constant.LOG_PATH);
        QbSdk.initX5Environment(mContext, this.cb);
    }

    public static MyApplication getInstances() {
        return instances;
    }

    private void setDatabase() {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(this, DB_NAME, null);
        this.mHelper = devOpenHelper;
        SQLiteDatabase writableDatabase = devOpenHelper.getWritableDatabase();
        this.db = writableDatabase;
        DaoMaster daoMaster = new DaoMaster(writableDatabase);
        this.mDaoMaster = daoMaster;
        this.mDaoSession = daoMaster.newSession();
    }

    public DaoSession getDaoSession() {
        return this.mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return this.db;
    }

    public void setDebug() {
        QueryBuilder.LOG_SQL = true;
        QueryBuilder.LOG_VALUES = true;
    }

    public void closeConnection() {
        closeHelper();
        closeDaoSession();
    }

    public void closeHelper() {
        DaoMaster.DevOpenHelper devOpenHelper = this.mHelper;
        if (devOpenHelper != null) {
            devOpenHelper.close();
            this.mHelper = null;
        }
    }

    public void closeDaoSession() {
        DaoSession daoSession = this.mDaoSession;
        if (daoSession != null) {
            daoSession.clear();
            this.mDaoSession = null;
        }
    }
}
